package com.harboursoftware.xstorage.unit.ac

import com.harboursoftware.xstorage.ac.GroupGrantee 
import com.harboursoftware.xstorage.model.XUser 
import org.junit.After 
import org.junit.Before 
import org.junit.Test 

class GroupGranteeTest {
	def allUsersGroupGrantee
	def authenticatedUsersGroupGrantee
	
	@Before
	void setUp() {
		allUsersGroupGrantee = GroupGrantee.ALL_USERS
		authenticatedUsersGroupGrantee = GroupGrantee.AUTHENTICATED_USERS
	}
	
	@After
	void tearDown() {
		allUsersGroupGrantee = null
		authenticatedUsersGroupGrantee = null
	}
	
	@Test
	void test_all_users_group_grantee_contains_user() {
		assert allUsersGroupGrantee.contains(new XUser())
	}
	
	@Test
	void test_all_users_group_grantee_contains_null() {
		assert allUsersGroupGrantee.contains(null)
	}
	
	@Test
	void test_authenticated_users_group_grantee_contains_user() {
		def user = new XUser(id : '41324312')
		assert authenticatedUsersGroupGrantee.contains(user)
	}
	
	@Test
	void test_authenticated_users_group_grantee_contains_null() {
		assert !authenticatedUsersGroupGrantee.contains(null)
	}
	
	@Test
	void test_authenticated_users_group_grantee_contains_user_with_null_id() {
		def user = new XUser()
		assert !authenticatedUsersGroupGrantee.contains(user)
	}
	
	@Test
	void test_toXML() {
		assert authenticatedUsersGroupGrantee.toXML() == '<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">' +
                 '<URI>http://acs.amazonaws.com/groups/global/AuthenticatedUsers<URI></Grantee>'
		
		assert allUsersGroupGrantee.toXML() == '<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">' +
		         '<URI>http://acs.amazonaws.com/groups/global/AllUsers<URI></Grantee>'
	}

}
